#include"stdafx.h"
#include "LogicProcess.h"

LogicProcess::LogicProcess(string cmdString,allTaskList *givenLists,allCommandStack *givenStacks){
	commandString=cmdString;
	allTask=givenLists;
	prevCmds=givenStacks;
	displayList=&allTask->getDisplayedList();
}

LogicProcess::LogicProcess(Task task,TaskList *list){
	needTask=task;
	needList=list;
}
int LogicProcess::cvtToNumber(string tmp){
	int result=0;
	int digit;
	for (int i=0;i<tmp.length();i++){
		digit=tmp[i]-48;
		result=result*10+digit;
	}
	return result;
}

void LogicProcess::pushToUndoList(Task task, commandType type, taskContainer container,bool needMore){
	CommandPackage package;
	package.setTask(task);
	package.setContainer(container);
	package.setType(type);
	package.setNeedProcessMore(needMore);

	prevCmds->getUndoCmds().push(package);

}

void LogicProcess::fromNeedtoDisplay(){
	allTask->getDisplayedList().clear();
	Task tmp;
	for (int i=0;i<needList->getLength();i++){
		needList->retrieve(i+1,tmp);
		allTask->getDisplayedList().add(tmp);
	}
}